<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\IntermediaryUser;
use App\Models\Company;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class IntermediaryUserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new IntermediaryUser(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('nickname');
            $grid->column('avatar')->image();
            $grid->column('password');
            $grid->column('company');
            $grid->column('old_house_num');
            $grid->column('rent_house_num');
            $grid->column('new_house_num');
            $grid->column('real_name');
            $grid->column('id_number');
            $grid->column('openid');
            $grid->column('session_key');
            $grid->column('mobile');
            $grid->column('gender');
            $grid->column('status');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new IntermediaryUser(), function (Show $show) {
            $show->field('id');
            $show->field('nickname');
            $show->field('avatar');
            $show->field('password');
            $show->field('company');
            $show->field('old_house_num');
            $show->field('rent_house_num');
            $show->field('new_house_num');
            $show->field('real_name');
            $show->field('id_number');
            $show->field('openid');
            $show->field('session_key');
            $show->field('mobile');
            $show->field('gender');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new IntermediaryUser(), function (Form $form) {
            $form->display('id');
            $form->text('nickname');
            $form->file('avatar')->disk('oss');
            $form->text('password');
            $data = Company::get()->pluck('company_name','id')->toArray();
            $form->select('company')->options($data);
            $form->text('old_house_num');
            $form->text('rent_house_num');
            $form->text('new_house_num');
            $form->text('real_name');
            $form->text('id_number');
            $form->text('openid');
            $form->text('session_key');
            $form->text('mobile');
            $form->radio('gender')->options(['男' => '男', '女'=> '女'])->default('男')->required();
            $form->radio('status')->options(['0' => '关闭', '1'=> '开启'])->default('0')->required();

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
